  var enlarging = false;
  function addEvent( obj, type, fn ) {
    if ( obj.attachEvent ) {
      obj['e'+type+fn] = fn;
      obj[type+fn] = function(){obj['e'+type+fn]( window.event );}
      obj.attachEvent( 'on'+type, obj[type+fn] );
    } else
      obj.addEventListener( type, fn, false );
  }
  function initPubblicita() {
    var pubdiv = document.getElementById("divPubblicita");
    var bt = document.getElementById("btOpenClosePubb");
    var dx = pubdiv.offsetLeft;
    var b = document.body;
    //pubdiv.style.left = "0px";
    
    if (! get_cookie("tix_pubb")) {
      var ora = new Date();
      var h = ora.getHours()+1;
      if (h > 23) h = 23;
      set_cookie("tix_pubb","OK",ora.getFullYear(),ora.getMonth(),ora.getDate(),h);
      onpubMouseOver();
      bt.className = "bottChiudiPubb";
    }
    
    //addEvent(pubdiv,"mouseover",onpubMouseOver);
    //addEvent(pubdiv,"mouseout",onpubMouseOut);
    
  }
  
  function aprichiudipubb() {
    var pubdiv = document.getElementById("divPubblicita");
    var pardiv = document.getElementById("parentPubb");
    var pdh = pubdiv.clientHeight+10;
    var bt = document.getElementById("btOpenClosePubb");
    if (pdh < 300) {
      onpubMouseOver();
      bt.className = "bottChiudiPubb";
    } else {
      onpubMouseOut();
      bt.className = "bottApriPubb";
    }
    
  }
  
  function onpubMouseOver() {
    enlarging = true;
    var pubdiv = document.getElementById("divPubblicita");
    var pardiv = document.getElementById("parentPubb");
    var pdh = pubdiv.clientHeight+50;
    pubdiv.style.height= pdh + "px";
    pardiv.style.height= pdh + "px";
    //checkScroll();
    if (pdh < 300) {
      window.setTimeout(onpubMouseOver,10);
    } else {
      enlarging = false;
      pubdiv.style.height= "300px";
      pardiv.style.height= "300px";
    }
  }
  function onpubMouseOut() {
    if (! enlarging) {
      var pubdiv = document.getElementById("divPubblicita");
      var pardiv = document.getElementById("parentPubb");
      var pdh = pubdiv.clientHeight-50;
      pubdiv.style.height= pdh + "px";
      pardiv.style.height= pdh + "px";
      //checkScroll();
    }
    if (pdh > 30) {
      window.setTimeout(onpubMouseOut,10);
    } else {
      pubdiv.style.height= "30px";
      pardiv.style.height= "30px";
    }
  }
  
  function checkScroll() {
    //alert("scroll" + document.body.scrollTop+","+document.body.scrollHeight);
    var pubdiv = document.getElementById("divPubblicita");
    var b = document.body;
    pubdiv.style.top = "" + (b.clientHeight-pubdiv.clientHeight+b.scrollTop) + "px";
  }
  
  function set_cookie ( name, value, exp_y, exp_m, exp_d, exp_h, path, domain, secure )
  {
    var cookie_string = name + "=" + escape ( value );
  
    if ( exp_y )
    {
      var expires = new Date ( exp_y, exp_m, exp_d,exp_h,59,59);
      cookie_string += "; expires=" + expires.toGMTString();
    }
  
    if ( path )
          cookie_string += "; path=" + escape ( path );
  
    if ( domain )
          cookie_string += "; domain=" + escape ( domain );
    
    if ( secure )
          cookie_string += "; secure";
    
    document.cookie = cookie_string;
  }
  
  function get_cookie ( cookie_name )
  {
    var results = document.cookie.match ( '(^|;) ?' + cookie_name + '=([^;]*)(;|$)' );
  
    if ( results )
      return ( unescape ( results[2] ) );
    else
      return null;
  }


  
  addEvent(window,"load",initPubblicita);
  //addEvent(window,"scroll",checkScroll);
